﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors.machines {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import __AS3__.vec.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class SlotMachineVO extends AbstractMachineVO {

        private static const RANDOM_ICONS_NAMES:Array = ["Flower", "Cucumber", "Cherry", "RewardBattery", "RewardXp"];
        private static const TYPE_BATTERY:String = "RewardBattery";
        private static const TYPE_3BATTERY:String = "Reward3Battery";
        private static const TYPE_XP:String = "RewardXp";
        private static const TYPE_ENERGY:String = "RewardEnergy";
        private static const TYPE_COINSTACK:String = "RewardCoinstack";
        private static const TYPE_GOLD:String = "RewardGold";
        private static const TYPE_COIN:String = "RewardCoin";

        public function SlotMachineVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
            state = WorldConstants.IDLE;
        }
        override public function getAction(_arg1:Object):InfoEvent{
            var _local2:Boolean;
            var _local3:InfoEvent;
            if (_arg1 == null){
                switch (state){
                    case WorldConstants.IDLE:
                        _local3 = this.handleIdle(_arg1);
                        dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_START_SLOTMACHINE));
                        break;
                    case WorldConstants.BUSY:
                        _local2 = false;
                        break;
                };
            } else {
                switch (_arg1.event){
                    case SlotMachineEvent.ON_SLOT_MACHINE_UPDATED:
                        state = WorldConstants.IDLE;
                        dispatch(new SlotMachineEvent(SlotMachineEvent.ON_SLOT_MACHINE_UPDATED));
                        break;
                };
            };
            if (_local2){
                dispatch(updateEvent);
            };
            return (_local3);
        }
        public function getSlotNamesList(_arg1:Vector.<RewardItemVO>):Array{
            var _local2:Array;
            var _local3:Boolean;
            var _local4 = "";
            if (((_arg1) && ((_arg1.length > 0)))){
                _local4 = _arg1[0].itemType;
                if (this.is3Batteries(_arg1)){
                    _local4 = TYPE_3BATTERY;
                };
            };
            switch (_local4){
                case TYPE_3BATTERY:
                    _local2 = [TYPE_3BATTERY, TYPE_3BATTERY, TYPE_3BATTERY];
                    this.playJackpotSound();
                    _local3 = true;
                    break;
                case TYPE_BATTERY:
                    _local2 = [TYPE_BATTERY, TYPE_BATTERY, TYPE_BATTERY];
                    _local3 = true;
                    break;
                case TYPE_XP:
                    _local2 = [TYPE_XP, TYPE_XP, TYPE_XP];
                    _local3 = true;
                    break;
                case TYPE_ENERGY:
                    _local2 = [TYPE_ENERGY, TYPE_ENERGY, TYPE_ENERGY];
                    _local3 = true;
                    break;
                case TYPE_COIN:
                    _local2 = [TYPE_COIN, TYPE_COIN, TYPE_COIN];
                    _local3 = true;
                    break;
                case TYPE_COINSTACK:
                    _local2 = [TYPE_COINSTACK, TYPE_COINSTACK, TYPE_COINSTACK];
                    _local3 = true;
                    break;
                case TYPE_GOLD:
                    _local2 = [TYPE_GOLD, TYPE_GOLD, TYPE_GOLD];
                    this.playJackpotSound();
                    _local3 = true;
                    break;
                default:
                    _local2 = [this.randomSlotIcon, TYPE_GOLD, this.randomSlotIcon];
                    _local3 = true;
                    break;
            };
            return ((_local3) ? Arrays.fastShuffle(_local2) : _local2);
        }
        private function playJackpotSound():void{
            var _local1:Object = new Object();
            _local1[EventConstants.SOUND_DELAY] = 1500;
            dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_JACKPOT_SLOTMACHINE, _local1));
        }
        private function is3Batteries(_arg1:Vector.<RewardItemVO>):Boolean{
            var _local3:RewardItemVO;
            var _local2:int;
            for each (_local3 in _arg1) {
                if (_local3.itemType == TYPE_BATTERY){
                    _local2++;
                };
            };
            return ((_local2 >= 3));
        }
        private function handleIdle(_arg1:Object):InfoEvent{
            var _local2:Array = [];
            state = WorldConstants.BUSY;
            var _local3:SlotMachineEvent = new SlotMachineEvent(SlotMachineEvent.START_ROLLING);
            _local3.machine_id = id;
            _local2.push(_local3);
            return (new InfoEvent(EventConstants.DISPATCH_DELAYED_EVENTS, null, _local2));
        }
        private function get randomSlotIcon():String{
            return (RANDOM_ICONS_NAMES[int((Math.random() * RANDOM_ICONS_NAMES.length))]);
        }

    }
}//package net.wooga.pets.models.world.vos.actors.machines 
